package com.next.aappublicapp.adapters;

import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.next.aap.client.AssemblyConstituencyWithCandidate;
import com.next.aappublicapp.R;

public class StateConstituencyCandidateListAdapter extends ArrayAdapter<AssemblyConstituencyWithCandidate> {
 
	public StateConstituencyCandidateListAdapter(Context context, List<AssemblyConstituencyWithCandidate> values) {
		super(context, R.layout.activity_state_constituency_candidate, values.toArray(new AssemblyConstituencyWithCandidate[values.size()]));
	}
 
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 
		View rowView = inflater.inflate(R.layout.assembly_constituency_candidate_row, parent, false);
		LinearLayout acRow = (LinearLayout)rowView.findViewById(R.id.ac_row);
		TextView textView = (TextView) rowView.findViewById(R.id.ac_name);
		TextView totalCandidatesView = (TextView) rowView.findViewById(R.id.ac_total_candidates);
		textView.setText(getItem(position).getName());
		totalCandidatesView.setText("Total Candidates = "+ (getItem(position).getnOfc()));
		if(position % 2 == 0){
			acRow.setBackgroundColor(Color.WHITE);
		}else{
			acRow.setBackgroundColor(Color.LTGRAY);
		}
		return rowView;
	}
}
